#!/usr/bin/env python
#
#    Copyright (C) 2013 Gonzalo Bonigo <gonzalobonigo@gmail.com>
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see http://www.gnu.org/licenses/
#


import os.path
import sys
import os

from daddydir import *


def _remove_pkg (pkg_name):
	for entry in os.listdir(pkg_name):
		if os.path.isdir(pkg_name + os.sep + entry):
			_remove_pkg(pkg_name + os.sep + entry)
		else:
			os.remove(pkg_name + os.sep + entry)
	os.rmdir(pkg_name)


if __name__ == '__main__':
	try:
		# Removing exceutable files...
		for f in EXEC_FILE_LIST:
			os.remove(EXEC_DIR + f)
		# Removing packages...
		for p in PKG_LIST:
			_remove_pkg(PKG_DIR + p)
	except (OSError,IOError) as error:
		print '\n' + str(error)
		print "\n--- Uninstall fails ---\n"
	else:
		print "\n--- Uninstall success ---\n"
